<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="Content-Script-Type" content="text/javascript" />
		<meta http-equiv="Content-Style-Type" content="text/css" />
		<title>コントロールパネル</title>
		<link rel="stylesheet" href="./assets/styles/default.css" type="text/css" />
		<link rel="stylesheet" href="./assets/styles/ui-lightness/ui.all.css" type="text/css" />
		<link rel="stylesheet" href="./assets/styles/ui-lightness/jquery-ui-1.7.3.custom.css" type="text/css" />
		<link rel="stylesheet" href="./assets/styles/dialog.css" type="text/css" />
		<script src="assets/scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
		<script src="assets/scripts/jquery-ui-1.7.3.custom.min.js" type="text/javascript"></script>
		<script src="assets/scripts/ui/ui.dialog.js" type="text/javascript"></script>
		<script src="assets/scripts/menu.js" type="text/javascript"></script>
		<script src="assets/scripts/table.js" type="text/javascript"></script>
		<script type="text/javascript" src="./assets/scripts/tiny_mce/tiny_mce.js"></script>
		<script type="text/javascript" src="./assets/scripts/editor.js"></script>
		<script type="text/javascript" src="./assets/scripts/ui/ui.datepicker.js"></script>
		<script type="text/javascript" src="./assets/scripts/ui/ui.core.js"></script>
		<script type="text/javascript" src="./assets/scripts/jquery.tablednd_0_5.js"></script>
		<script type="text/javascript" src="./assets/scripts/search.js"></script>
		<script type="text/javascript">
		$(function() {
			$('.message').fadeIn("slow");
			$('.btn_regist').click(function(){
				if( confirm('登録してよろしいですか？') ){
					document.fm.mode.value = 'input';
					document.fm.submit();
				}
			});
			
			$('.btn_update').click(function(){
				if( confirm('更新してよろしいですか？') ){
					document.fm.mode.value = 'input';
					document.fm.submit();
				}
			});
			$('.btn_return').click(function(){
				location.href = "mareaad_index.php?hist=2";
			});
			
			$('.text_date').datepicker({
				changeMonth: true,
				changeYear: true,
				dateFormat: 'yy/mm/dd'
			});
			
			$("#area_cd").change(function(){
				document.fm.area_name.value = $("#area_cd").find("option:selected").text();
			});
			
			
			$('#button_addItem').click(function(){
				init();
			});
			
			$('button.tddel').live('click',function(){
				$(this).closest('tr').remove();
				$('#p_count').val(get_class_sum('nper'));
				$('#n_count').val(get_class_sum('nnum'));
			});
		
			$('input.nper').live('change',function(){
				
				var idarr = $(this).attr("id").split("_");
				var x =   Math.round($(this).val() * $('#area_nums').val() /100) ;
				$('#n_'+ idarr[1]).val(x);
				
				$('#p_count').val(get_class_sum('nper'));
				$('#n_count').val(get_class_sum('nnum'));
				//zuoshow($('.nper').get(1));
				//$('#aaaa').printObj($('.nper').get(1),"aaaa");
				//zuoshow($('.nper').get(1));
			});
			$('#year4').change(function(){
				var year4 = this.value;
				var myDate = new Date();
				var nowtime =  myDate.getTime();
					
				$.get("mmap_week_ajax.php",{ y: year4,t : nowtime }, function(data){
					$("#week_cd").children().remove();
					$("#week_cd").append( data ); 
				});
			});
			$('#area_nums').change(function(){
				$('.nper').each(function(){
					var idarr = $(this).attr("id").split("_");
					var x =   Math.round($(this).val() * $('#area_nums').val() /100) ;
					$('#n_'+ idarr[1]).val(x);
				});
				$('#p_count').val(get_class_sum('nper'));
				$('#n_count').val(get_class_sum('nnum'));
			});
			
			$('#p_count').val(get_class_sum('nper'));
			$('#n_count').val(get_class_sum('nnum'));
			
		});
		
		function get_class_sum(classid){
			var retsum = 0;
			$('.'+ classid).each(function(){
				retsum = retsum +  $(this).val() *1;
				//alert($(this).attr("id"));
			});
			return retsum;
		}
		/*
		function setSS( valcd, valnm ) {
			document.fm.shop_cd.value = valcd;
			document.fm.shop_name.value = valnm;			
			$('#dialog').dialog("close");
		}
		*/
		function setS(  valnm ) {
			//eval("document.fm." +  gPara + "_cd.value = " + valcd);
			eval("document.fm." +  gPara + "_name.value ='" + valnm + "'");			
			$('#dialog').dialog("close");
		}
		
		function li_add(objID,inID, inVal) {
			if (checkNames(inID)) {
				var strHtml = "<li id='a" + inID +"' class='item_li'> <a href='#'  style='color:red' class='li_del' >X</a>&nbsp;&nbsp;"+ inID + "&nbsp;&nbsp;" + inVal;
				if (typeof(g_shop_ul_to_grid)!="undefined") {
					strHtml = strHtml + "<input type='hidden' value='" + inID  + "' name ='"  + gMutiObj + "_cd_ul[]'>";
					strHtml = strHtml + "<input type='hidden' value='" + inVal + "' name ='" + gMutiObj + "_name_ul[]'>";
				} else {
					strHtml = strHtml + "<input type='hidden' value='" + inID  + "' name ='"  + gMutiObj + "_cd[]'>";
					strHtml = strHtml + "<input type='hidden' value='" + inVal + "' name ='" + gMutiObj + "_name[]'>";
				}
				strHtml = strHtml + "</li>";
				$("#" + objID +"_ul").append(strHtml);
			}
		}
		var g_shop_ul_to_grid = true ;
		function add_tr(vid, vname) {
			var table = $('#table_shop');
			var str = '<tr><td> ' + vid + '</td><td>' + vname + ' </td><td> <input type="text" id="p_'+ vid +'" name='  + gMutiObj + '_per[]" class="text nper" value = ""/> ';
			str = str + "<input type='hidden' value='" + vid  + "' name ='"  + gMutiObj + "_cd[]'>";
			str = str + "<input type='hidden' value='" + vname + "' name ='" + gMutiObj + "_name[]'>";
			str = str + '<td> <input type="text"  id="n_'+ vid +'"  name='   + gMutiObj + '_nums[]" class="text nnum"  readonly="readonly" value = ""/></td> '
			str = str + '<td align="center"><button type="button" class="tddel">削除</button> </td></tr>';
			$(table).append(str);
		}
		
		function copy_shop_pop_ul_to_grid() {
			var cdsul   = document.getElementsByName(gMutiObj + '_cd_ul[]');
			var namesul = document.getElementsByName(gMutiObj + '_name_ul[]');
			var cdarr   = new Array();
			$.each(cdsul, function(i,val){
				cdarr[i] = val.value;
			}); 
			var html = $("#table_shop tr:last").html();
            html = "<tr>" + html + "</tr>";
            $("#table_shop tr:last").remove();
			$.each(namesul, function(i,val){
				add_tr(cdarr[i], val.value)
			}); 
			$("#table_shop").append(html);
		}
		</script>
		
	</head>
	<body id="">
{{ $menu }}
{{ $logout }}
		<div id="container"><div class="wrapper">
			<h2>地域広告マスター管理</h2>
			<ul class="submenu clearfix">
				<li><a href="mareaad_index.php">地域広告情報一覧</a></li>
				<li>地域広告情報登録</li>
				<li><a href="mareaad_import.php">基本情報CSV登録</a></li>
				{{ if $notisg5 }}<li><a href="mareaad_shop_import.php">店舗情報CSV登録 </a></li>{{/if}}
				<li><a href="marea_index.php">DNPエリアマスタ</a></li>
			</ul>


			<h3>{{ if $isshop == '1' }}地域広告店舗情報{{ else }}地域広告情報{{ /if }}{{ if $forms.id == '' }}登録{{ else }}更新{{ /if }}{{ if $phase == 'complete' }}完了{{ /if }}</h3>
{{ if $phase == 'input' }}
			<p class="message">内容を確認し、{{ if $forms.id == '' }}登録{{ else }}更新{{ /if }}ボタンをクリックしてください。</p>
			<form name="fm" action="mareaad_form.php" method="post">
				<table class="formTable">
					<tbody>
{{ if $forms.id != '' }}
						<tr>
							<th>更新日</th>
							<td>
								{{ $forms.u_time }}<input type="hidden" name="u_time" value="{{ $forms.u_time }}" />
							</td>
						</tr>
						<tr>
							<th>更新者</th>
							<td>
								{{ $forms.m_user_name }}<input type="hidden" name="m_user_name" value="{{ $forms.m_user_name }}" />
							</td>
						</tr>
						<tr>
							<th>ID</th>
							<td>{{ $forms.id }}</td>
						</tr>
{{else}}
{{ /if }}
						<tr>
							<th><span>※</span>エリア名</th>
							<td>
								{{ if $editflg==1 &&  $isshop!=1 }}
								{{ html_options id='area_cd' name='area_cd' options=$area selected=$forms.area_cd }}{{ $err.area_cd }}
								<input type="hidden" name="area_name"  value="{{ $forms.area_name|escape }}" />
								{{ else }}
									{{ $forms.area_name }}
									<input type="hidden" name="area_cd"    value="{{ $forms.area_cd|escape }}" />
									<input type="hidden" name="area_name"  value="{{ $forms.area_name|escape }}" />
								{{ /if }}
							</td>
						</tr>
						<tr>
							<th><span>※</span>配布エリア名</th>
							<td>
								{{ if $editflg==1  &&  $isshop!=1 }}
									<input type="text" name="publish_area_name" class="text" value="{{ $forms.publish_area_name|escape }}" />{{ $err.publish_area_name }}
									<button type="button" id="publish_area" class="btn_search" rel="publish_area"><span>参照</span></button>
								{{ else }}
									{{ $forms.publish_area_name }}<input type="hidden" name="publish_area_name"  value="{{ $forms.publish_area_name|escape }}" />
								{{ /if }}
							</td>
						</tr>
						<tr>
							<th><span>※</span>エリア部数</th>
							<td>
							{{ if $isshop!=1 }}
								<input type="text" name="area_nums" id="area_nums" class="text" value="{{ $forms.area_nums }}" />{{ $err.area_nums }}
							{{ else }}
									{{ $forms.area_nums|number_format }}<input type="hidden"  name="area_nums" id="area_nums"  value="{{ $forms.area_nums }}" />
							{{ /if }}
							</td>
						</tr>
						<tr>
							<th><span>※</span>取扱業者</th>
							<td>
								{{ if $editflg==1  &&  $isshop!=1 }}
									<input type="text" name="hand_name" class="text" value="{{ $forms.hand_name|escape }}" />{{ $err.hand_name }}
									<button type="button" id="hand" class="btn_search" rel="hand"><span>参照</span></button>
								{{ else }}
									{{ $forms.hand_name }}<input type="hidden" name="hand_name"  value="{{ $forms.hand_name|escape }}" />
								{{ /if }}
							</td>
						</tr>
						<tr>
							<th><span>※</span>媒体名</th>
							<td>
								{{ if $editflg==1  &&  $isshop!=1 }}
									<input type="text" name="media_name" class="text" value="{{ $forms.media_name|escape }}" />{{ $err.media_name }}
									<button type="button" id="media" class="btn_search" rel="media"><span>参照</span></button>
								{{ else }}
									{{ $forms.media_name }}<input type="hidden" name="media_name"  value="{{ $forms.media_name|escape }}" />
								{{ /if }}
							</td>
						</tr>
						<tr>
							<th><span>※</span>配布日</th>
							<td>
								{{ if $editflg==1  &&  $isshop!=1 }}
									{{ html_options id='year4' name='year4' options=$year4 selected=$forms.year4 }} 年{{ $err.year4 }}
									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ html_options id='week_cd' name='week_cd' options=$week  selected=$forms.week_cd }}{{ $err.week_cd }} 週
								{{ else }}
									{{ $forms.begin_date }}<input type="hidden" name="week_cd"  value="{{ $forms.week_cd|escape }}" />
								{{ /if }}
							</td>
						</tr>
						<tr>
							<th>備考</th>
							<td>
								{{ if $editflg==1  &&  $isshop!=1 }}
									<textarea name="memo" class="textarea"  style="width:380px" />{{ $forms.memo|escape }}</textarea>{{ $err.memo }}
								{{ else }}
									{{ $forms.memo }} <input type="hidden" name="memo"  value="{{ $forms.memo }}" />
								{{ /if }}
							</td>
						</tr>
{{ if $forms.id != '' }}
						<tr>
							<th><span>※</span>店舗</th>
							<td>
			{{ if $isshop == '1' }}  
					<button type="button" id="shop" class="btn_search_muti" ><span>店舗追加</span></button> {{ $err.mutirow }}
			{{ /if }}
				<table  style="width:85%" id="table_shop">

					<thead>
						<tr>
							<th>店舗コード</th>	<th>店舗名</th>	<th>店舗部数%</th>	<th>計算部数</th>	{{ if $isshop == '1' }}<th>操作</th>{{ /if }}
						</tr>
					</thead>
					<tbody>
{{ foreach from=$forms.mutirow key=k item=v name="member" }}
						<tr>
							<td> {{ $v.shop_cd }} </td>
							<td> {{ $v.shop_name }} </td>
							<td> 
					{{ if $isshop == '1' }}
								<input class="text nper" type="text" value="{{ $v.shop_per }}"  id="p_{{ $v.shop_cd }}" name="shop_per[]">{{ $err.shop_per[$smarty.foreach.member.index] }}
					{{ else }}
								<input class="dtext nper" type="text" value="{{ $v.shop_per }}"  id="p_{{ $v.shop_cd }}" name="shop_per[]" readonly>
					{{ /if }}
								<input type="hidden" name="shop_cd[]" value="{{ $v.shop_cd }}">
								<input type="hidden" name="shop_name[]" value="{{ $v.shop_name }}">
							</td>
							<td>
							{{ if $isshop == '1' }}
								<input class="text nnum" type="text" value="{{ $v.shop_nums }}" id="n_{{ $v.shop_cd }}" readonly="readonly" name="shop_nums[]">
							{{ else }}
								<input class="dtext nnum" type="text" value="{{ $v.shop_nums }}" id="n_{{ $v.shop_cd }}" readonly="readonly" name="shop_nums[]">
							{{ /if }}
							</td>
				{{ if $isshop == '1' }}
							<td align="center">
								<button type="button" class="tddel">削除</button>
							</td>
				{{ /if }}
						</tr>
{{ /foreach }}
						<tr><td {{ if $isshop == '1' }}colspan='2' {{ /if }} align="center"> 合計 </td>
						<td><input class="dtext" type="text"  id="p_count" readonly="readonly" name="p_count"></td>
						<td><input class="dtext" type="text"  id="n_count" readonly="readonly" name="n_count"></td>	<td> &nbsp; </td>	
						</tr>
					</tbody>
				</table>
							</td>
						</tr>
 {{ /if }}

					</tbody>
				</table>
				<p class="button">
{{ if $forms.id != '' }}
					<button type="button" class="btn_return" class="submit"><span>戻る</span></button>
					<button type="button" class="btn_update" class="submit"><span>更新</span></button>
{{ else }}
					<button type="button" class="btn_regist" class="submit"><span>登録</span></button>
{{ /if }}
				</p>
				<input type="hidden" name="id" value="{{ $forms.id }}" />
				<input type="hidden" name="isshop" value="{{ $isshop }}" />
				<input type="hidden" name="mode" value="" />
			</form>

<div id="dialog" >
</div>
 <div id="dialogmuti" >
</div>

{{ /if }}

{{ if $phase == 'complete' }}
			<p class="message">{{ $message }}</p>
			<ul>
{{ if $forms.id != '' }}
				<li>>> <a href="mareaad_index.php?hist=2">一覧ページに戻る</a></li>
{{ else }}
				<li>>> <a href="mareaad_index.php">一覧ページに戻る</a></li>
{{ /if }}
				<li>>> <a href="mareaad_form.php">新規登録</a></li>
{{ if $forms.id != '' }}
				<li>>> <a href="mareaad_form.php?id={{ $forms.id }}{{ if $isshop == '1' }}&isshop=1{{ /if }}">更新</a></li>
{{ /if }}
			</ul>
{{ /if }}

		</div></div>
		{{ $footer }}
	</body>
</html>